
*** Below, insert the path on your computer, where you have saved the file "fulldata.dta" ***

use "...fulldata.dta"   

***** Organizing data *****

keep id wave satDemUK euRefVote trustMPs approveUKGovt handleEUNegotiate gender age edlevel partyId

reshape wide euRefVote satDemUK trustMPs approveUKGovt handleEUNegotiate gender age edlevel partyId, i(id) j(wave)

*** Keeping respondents who can be identified as Leave -or Remain-voters in the wave before the referendum (wave 8)

keep if euRefVote8 == 0 | euRefVote8 == 1 

*** Coding Leave/Remain-status in all waves

replace euRefVote1 = 1 if euRefVote8 == 1 & euRefVote1 !=.

replace euRefVote1 = 0 if euRefVote8 == 0 & euRefVote1 !=.

replace euRefVote2 = 1 if euRefVote8 == 1 & euRefVote2 !=.

replace euRefVote2 = 0 if euRefVote8 == 0 & euRefVote2 !=.

replace euRefVote3 = 1 if euRefVote8 == 1 & euRefVote3 !=.

replace euRefVote3 = 0 if euRefVote8 == 0 & euRefVote3 !=.

replace euRefVote4 = 1 if euRefVote8 == 1 & euRefVote4 !=.

replace euRefVote4 = 0 if euRefVote8 == 0 & euRefVote4 !=.

replace euRefVote5 = 1 if euRefVote8 == 1 & euRefVote5 !=.

replace euRefVote5 = 0 if euRefVote8 == 0 & euRefVote5 !=. 

replace euRefVote6 = 1 if euRefVote8 == 1 & euRefVote6 !=.

replace euRefVote6 = 0 if euRefVote8 == 0 & euRefVote6 !=.

replace euRefVote7 = 1 if euRefVote8 == 1 & euRefVote7 !=.

replace euRefVote7 = 0 if euRefVote8 == 0 & euRefVote7 !=.

replace euRefVote9 = 1 if euRefVote8 == 1 & euRefVote9 !=.

replace euRefVote9 = 0 if euRefVote8 == 0 & euRefVote9 !=.

replace euRefVote10 = 1 if euRefVote8 == 1 & euRefVote10 !=.

replace euRefVote10 = 0 if euRefVote8 == 0 & euRefVote10 !=.

replace euRefVote11 = 1 if euRefVote8 == 1 & euRefVote11 !=.

replace euRefVote11 = 0 if euRefVote8 == 0 & euRefVote11 !=.

replace euRefVote12 = 1 if euRefVote8 == 1 & euRefVote12 !=.

replace euRefVote12 = 0 if euRefVote8 == 0 & euRefVote12 !=.

replace euRefVote13 = 1 if euRefVote8 == 1 & euRefVote13 !=.

replace euRefVote13 = 0 if euRefVote8 == 0 & euRefVote13 !=.

replace euRefVote14 = 1 if euRefVote8 == 1 & euRefVote14 !=.

replace euRefVote14 = 0 if euRefVote8 == 0 & euRefVote14 !=.

replace euRefVote15 = 1 if euRefVote8 == 1 & euRefVote15 !=.

replace euRefVote15 = 0 if euRefVote8 == 0 & euRefVote15 !=.

replace euRefVote16 = 1 if euRefVote8 == 1 & euRefVote16 !=.

replace euRefVote16 = 0 if euRefVote8 == 0 & euRefVote16 !=.

replace euRefVote17 = 1 if euRefVote8 == 1 & euRefVote17 !=.

replace euRefVote17 = 0 if euRefVote8 == 0 & euRefVote17 !=.

replace euRefVote18 = 1 if euRefVote8 == 1 & euRefVote18 !=.

replace euRefVote18 = 0 if euRefVote8 == 0 & euRefVote18 !=.

replace euRefVote19 = 1 if euRefVote8 == 1 & euRefVote19 !=.

replace euRefVote19 = 0 if euRefVote8 == 0 & euRefVote19 !=.

reshape long satDemUK trustMPs euRefVote approveUKGovt handleEUNegotiate gender age edlevel partyId, i(id) j(wave)

recode satDemUK (9999=.)

recode trustMPs (9999=.)

*** Equal range in the dependent measures (0-1) ***

foreach var in satDemUK trustMPs {

		qui sum `var'

		replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')

	}

label define wave 1 "Feb/March 2014" 2 "May/June 2014" 3 "Sep/Oct 2014" 4 "March 2015" 5 "April/May 2015" 6 "May 2015" 7 "April/May 2016" 8 "May/June 2016" 9 "June/July 2016" 10 "Nov/Dec 2016" 11 "April/May 2017" 12 "May/June 2017" 13 "June 2017" 14 "May 2018" 15 "March 2019" 16 "May/June 2019" 17 "November 2019" 18 "Nov/Dec 2019" 19 "December 2019"

label values wave wave

************************************************************************************************************************

*** Generating means on the outcomes for Leave and Remain-voters ***

egen mean_satdem_w = mean(satDemUK) if euRefVote==1, by(wave)

egen mean_satdem_l = mean(satDemUK) if euRefVote==0, by(wave)

egen mean_trustmp_w = mean(trustMPs) if euRefVote==1, by (wave)

egen mean_trustmp_l = mean(trustMPs) if euRefVote==0, by (wave)

*** Calculating outcome means for Leave (winners) and Remain (losers), respectively - over waves ***

mean mean_satdem_w, over(wave)

mean mean_satdem_l, over(wave)

mean mean_trustmp_w, over(wave)

mean mean_trustmp_l, over(wave)

*** The above means are stored in a new data set called "BES_WL_plotdata_v2" ***

************************************************************************************************************************

***** In the following regressions, the interactions terms are used and plotted in the lower panels of Figure 1 *****

*** DID: satisfaction with democracy ***

reg satDemUK i.wave##i.euRefVote if wave==1|wave==2

reg satDemUK i.wave##i.euRefVote if wave==2|wave==3

reg satDemUK i.wave##i.euRefVote if wave==3|wave==4

reg satDemUK i.wave##i.euRefVote if wave==4|wave==6

reg satDemUK i.wave##i.euRefVote if wave==6|wave==7

reg satDemUK i.wave##i.euRefVote if wave==7|wave==8

reg satDemUK i.wave##i.euRefVote if wave==8|wave==9

reg satDemUK i.wave##i.euRefVote if wave==9|wave==10

reg satDemUK i.wave##i.euRefVote if wave==10|wave==11

reg satDemUK i.wave##i.euRefVote if wave==11|wave==13

reg satDemUK i.wave##i.euRefVote if wave==13|wave==15

reg satDemUK i.wave##i.euRefVote if wave==15|wave==16

reg satDemUK i.wave##i.euRefVote if wave==16|wave==17

reg satDemUK i.wave##i.euRefVote if wave==17|wave==19


*** DID: trust in MPs ***
reg trustMPs i.wave##i.euRefVote if wave==1|wave==2

reg trustMPs i.wave##i.euRefVote if wave==2|wave==3

reg trustMPs i.wave##i.euRefVote if wave==3|wave==4

reg trustMPs i.wave##i.euRefVote if wave==4|wave==6

reg trustMPs i.wave##i.euRefVote if wave==6|wave==7

reg trustMPs i.wave##i.euRefVote if wave==7|wave==8

reg trustMPs i.wave##i.euRefVote if wave==8|wave==9

reg trustMPs i.wave##i.euRefVote if wave==9|wave==10

reg trustMPs i.wave##i.euRefVote if wave==10|wave==12

reg trustMPs i.wave##i.euRefVote if wave==12|wave==15

reg trustMPs i.wave##i.euRefVote if wave==15|wave==16

reg trustMPs i.wave##i.euRefVote if wave==16|wave==17

reg trustMPs i.wave##i.euRefVote if wave==17|wave==18

reg trustMPs i.wave##i.euRefVote if wave==18|wave==19

************************************************************************************************************************

***** The following code reproduces the DID-results in Tables 3-6 *****
* Table 3
by euRefVote, sort : ttest trustMPs if wave==10|wave==12, by(wave)
by wave, sort : ttest trustMPs if wave==10|wave==12, by(euRefVote)
reg trustMPs i.wave##i.euRefVote if wave==10|wave==12

by euRefVote, sort : ttest satDemUK if wave==10|wave==11, by(wave)
by wave, sort : ttest satDemUK if wave==10|wave==11, by(euRefVote)
reg satDemUK i.wave##i.euRefVote if wave==10|wave==11

* Table 4
by euRefVote, sort : ttest trustMPs if wave==12|wave==16, by(wave)
by wave, sort : ttest trustMPs if wave==12|wave==16, by(euRefVote)
reg trustMPs i.wave##i.euRefVote if wave==12|wave==16

by euRefVote, sort : ttest satDemUK if wave==13|wave==16, by(wave)
by wave, sort : ttest satDemUK if wave==13|wave==16, by(euRefVote)
reg satDemUK i.wave##i.euRefVote if wave==13|wave==16

* Table 5
by euRefVote, sort : ttest trustMPs if wave==12|wave==15 & euRefVote !=., by(wave)
by wave, sort : ttest trustMPs if wave==12|wave==15, by(euRefVote)
reg trustMPs i.wave##i.euRefVote if wave==12|wave==15

by euRefVote, sort : ttest satDemUK if wave==13|wave==15 & euRefVote !=., by(wave)
by wave, sort : ttest satDemUK if wave==13|wave==15, by(euRefVote)
reg satDemUK i.wave##i.euRefVote if wave==13|wave==15

* Table 6
by euRefVote, sort : ttest trustMPs if wave==15 & euRefVote !=.|wave==16 & euRefVote !=., by(wave)
by wave, sort : ttest trustMPs if wave==15|wave==16, by(euRefVote)
reg trustMPs i.wave##i.euRefVote if wave==15|wave==16

by euRefVote, sort : ttest satDemUK if wave==15 & euRefVote !=.|wave==16 & euRefVote !=., by(wave)
by wave, sort : ttest satDemUK if wave==15|wave==16, by(euRefVote)
reg satDemUK i.wave##i.euRefVote if wave==15|wave==16


